package io.bdmc.modules.bss.service.impl;

import io.bdmc.common.annotation.DataFilter;
import io.bdmc.common.utils.MyPage;
import io.bdmc.modules.bss.entity.SmkDevice;
import io.bdmc.modules.bss.entity.SmkShop;
import io.bdmc.modules.bss.mapper.SmkShopMapper;
import io.bdmc.modules.bss.model.LabelValue;
import io.bdmc.modules.bss.model.ShopLocation;
import io.bdmc.modules.bss.model.ShopParam;
import io.bdmc.modules.bss.service.ISmkShopService;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author huang lu
 * @since 2019-01-21
 */
@Service
public class SmkShopServiceImpl extends ServiceImpl<SmkShopMapper, SmkShop> implements ISmkShopService {

    @Autowired
    private SmkShopMapper shopMapper;

    @DataFilter(tableAlias = "d", user = false)
    @Override
    public MyPage<SmkShop> mySelectPage(MyPage<SmkShop> page, ShopParam shopParam) {
        return shopMapper.mySelectPage(page, shopParam);
    }

    @DataFilter(tableAlias = "d", user = false)
    @Override
    public List<LabelValue> mySelectByDept(MyPage<SmkShop> page, ShopParam shopParam) {
        return shopMapper.mySelectByDept(page, shopParam);
    }

    @Override
    public List<ShopLocation> myLocations(Long deptId) {
        return shopMapper.selectLocationByDepId(deptId);
    }

    @Override
    public MyPage<ShopLocation> getByDepId(MyPage<SmkShop> myPage, ShopParam shopParam) {
        return shopMapper.getByDepId(myPage, shopParam);
    }

    @Override
    public Long countByDepId(Long deptId) {
        return shopMapper.countByDepId(deptId);
    }

    @Override
    public List<Map<String, Object>> getShopLatLng(Long deptId) {
        return shopMapper.getShopLatLng(deptId);
    }

    @Override
    @Transactional
    public Boolean updateShopAndDevDept(SmkShop shop, List<SmkDevice> devs) {
        shop.updateById();
        for (SmkDevice dev : devs) {
            dev.setDeptId(shop.getDeptId());
            dev.updateById();
        }
        return true;
    }
    

}
